﻿using Microsoft.Extensions.Configuration;
using OA.Core.DataAccessHelper;
using OA.Core.Helper;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OA.Model.Mapper
{
    public class VoucherMapper : ITableMappable
    {
        private static Dictionary<int, string> dic = new Dictionary<int, string>();
        public string GetMappingTableName(Type modelType, object customFormID)
        {
            int id = (int)customFormID;
            if (dic.ContainsKey(id)) return dic[id];
            using (var dbContext = new MyDbContext())
            {
                var list=dbContext.CustomForm.Select(m => new { m.ID, m.TableName }).ToList();
                foreach (var item in list)
                {
                    if(dic.ContainsKey(item.ID))
                    {
                        dic[item.ID] = "Z_" + item.TableName;
                    }
                    else
                    {
                        dic.TryAdd(item.ID, "Z_" + item.TableName);
                    }
                }
            }
            if (dic.ContainsKey(id)) return dic[id];
            throw new Exception("没有找到当前类型对应的表名");
        }
    }
    
}
